﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.Entity;
using ClassLibrary.DAO;
using System.IO;

public partial class en_GetCodeImage : System.Web.UI.Page
{
    TblImagesDAO ImageDAO = new TblImagesDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadIamge();
            LoadImagePhoto();
            String strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
            //TextBox2.Text = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/") + "admin/img/images/150163D.png";
        }
    }

    private void LoadImagePhoto()
    {
        string IdAl = Request.QueryString["IdAl"];
        GrdImageByIDAlbum.DataSource = ImageDAO.GetImageByIdAlbum(Convert.ToInt32(IdAl));
        GrdImageByIDAlbum.DataBind();
    }

    private void LoadIamge()
    {
        string idImg = Request.QueryString["IdImg"];
        TblImages image = ImageDAO.GetImageByID(Convert.ToInt32(idImg));
        //txt.Text = image.IDImage.ToString();
        //TextBox1.Text = image.ImageURL;
        //String strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
        //TextBox2.Text = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/") +"Admin/img/images/" + image.ImageURL;
    }
    protected void GrdImageByIDAlbum_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HiddenField hidItemID = (HiddenField)e.Row.Cells[0].FindControl("hidItemID");
            hidItemID.Value = DataBinder.Eval(e.Row.DataItem, "IDImage").ToString();
            string idImg = hidItemID.Value;
            TblImages image = ImageDAO.GetImageByID(Convert.ToInt32(idImg));
            TextBox txtCode = (TextBox)e.Row.Cells[0].FindControl("txtCode");
            String strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
            string url = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/") + "Admin/img/images/" + image.ImageURL;
            txtCode.Text = "<img src=\"" + url + "\"" + " alt=\"" + "code image \"" + " style=\"" + " border:0\"" + " />" + "\n";
        }
    }
}
